/**
 * File: GraphMapper.java
 * Created by: mhaimel
 * Created on: Mar 8, 2010
 * CVS:  $Id: GraphMapper.java 1.0 Mar 8, 2010 4:19:28 PM mhaimel Exp $
 */
package uk.ac.ebi.curtain.model.graph.io;

import uk.ac.ebi.curtain.model.graph.Graph;
import uk.ac.ebi.curtain.model.graph.impl.ConcurrentGraph;

/**
 * @author mhaimel
 *
 */
@SuppressWarnings("unchecked")
public class GraphMapper implements WriteMapper<Graph>, ReadMapper<Graph> {

	private static final String[] header = new String[]{"Node_Count","Arc_Count"};

	@Override
	public String[] getHeader() {
		return header;
	}

	@Override
	public Object[] toArray(Graph value) {
		return new Object[]{
				value.getNodeSize(),
				value.getArcCount()
		};
	}

	@Override
	public int getFieldCount() {
		return header.length;
	}

	protected Graph buildNewGraph(Long node) {
		return new ConcurrentGraph(node);
	}

	@Override
	public Graph loadValue(String[] array, int i, Graph graph) {
		Long node = Long.valueOf(array[i++]);
		Long arc = Long.valueOf(array[i++]);
		Graph newGraph = graph.buildNewGraph(node);
		newGraph.forceSetArcCount(arc);
		return newGraph;
	}
	
}
